<template>
  <div >
    <div>
      <div class="font15 mt10 pl10">
      <span class="titletext ">{{titledata.title}}</span>
      <div class="graytext  mt10 font13">
        <span >工单编号：</span>
        <span class="titletext">{{titledata.pmInsId}}</span>
      </div>
    </div>
    <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">应标管理数据</span> 
    </div>
    <van-field readonly required name="city" :value="fromdata.city" label="地市：" label-width="3em" />
    <!-- <van-field v-if="fromdata.city!='省重要客户中心'" :right-icon="canEditcountiesPick?'arrow':''" readonly required name="counties" :value="fromdata.counties" label="县区：" label-width="3em"  @click="canEditcountiesPick==true?getCountyByParentOrgCode():''"/> -->
     <van-field v-if="fromdata.city!='省重要客户中心'" readonly required name="counties" :value="fromdata.counties" label="县区：" label-width="3em"  />
    <van-popup v-model="showcountiesPick" position="bottom" get-container="body">
      <van-picker show-toolbar :columns="showcountiesPickcolumns" @confirm="showcountiesPickonConfirm" @cancel="showcountiesPick = false"/>
    </van-popup> 
    <van-field readonly required name="projectName" :value="fromdata.projectName" label="项目名称：" label-width="5em" />
    <van-field readonly required name="biddingBudget" :value="fromdata.biddingBudget" label="招标预算(万元)：" label-width="8.5em" />
    <van-field readonly name="openBiddingTime" :value="fromdata.openBiddingTime" label="开标时间：" label-width="5em" />
    <van-field readonly required name="biddingPeople" :value="fromdata.biddingPeople" label="招标人：" label-width="4em" />
    <van-field readonly required name="dataTime" :value="fromdata.dataTime" label="数据时间：" label-width="5em" />
    <van-field readonly required name="tenderDate" :value="fromdata.tenderDate" label="招标公告日期：" label-width="7em" />
    <van-field readonly required name="announcementUrl" :value="fromdata.announcementUrl" label="公告链接：" label-width="5em" />
    <van-field readonly required name="purchasingMethod" :value="fromdata.purchasingMethod" label="采购方式：" label-width="5em" />
    <van-field readonly required name="biddingMethod" :value="fromdata.biddingMethod" label="投标方式：" label-width="5em" />
    <van-field readonly name="closeRegistrationTime" :value="fromdata.closeRegistrationTime" label="截止报名时间：" label-width="7em" />
    <van-field readonly required name="biddingFileAmount" :value="fromdata.biddingFileAmount" label="招标文件购买金额(元)：" label-width="11.5em" />
    <van-field readonly required name="biddingAgency" :value="fromdata.biddingAgency" label="招标代理机构：" label-width="7em" />
    <van-field readonly required name="contactPerson" :value="fromdata.contactPerson" label="联系人：" label-width="4em" />
    <van-field readonly required name="contactPersonTel" :value="fromdata.contactPersonTel" label="联系电话：" label-width="5em" />
    <van-field readonly required name="industryAttribution" :value="fromdata.industryAttribution" label="一级行业归属：" label-width="7em" />
    <van-field readonly required name="processLimited" :value="fromdata.processLimited" label="处理时限(天)：" label-width="7.5em" />
    <van-field readonly required name="dataSources" :value="fromdata.dataSources" label="数据来源：" label-width="5em" />

    <van-field  readonly required name="isClaimValue" :value="fromdata.isClaimValue" label="是否认领(地市公司)：" label-width="10.5em" @click="showdishiPick1 = (canEditdishi==true&&fromdata.city=='省重要客户中心')?true:false" :right-icon="canEditdishi&&fromdata.city=='省重要客户中心' ? 'arrow' : ''"/>
    <van-popup v-model="showdishiPick1" position="bottom" get-container="body">
      <van-picker show-toolbar :columns="showdishiPick1columns" @confirm="showdishiPick1onConfirm" @cancel="showdishiPick1 = false"/>
    </van-popup> 
    <van-field v-if="showNodishi1Filed==true" :readonly="canEditdishi!=true" required autosize type="textarea" rows="1" name="isClaimDescription" :value="fromdata.isClaimDescription" v-model="fromdata.isClaimDescription" label="非本地市项目说明：" label-width="9em" :rules="[{ required: showNodishi1Filed, message: '请填写说明'}]" :right-icon="canEditdishi ? 'arrow' : ''"/>
    <van-field readonly required name="isOperateCity" :value="fromdata.isOperateCity" label="是否公司经营范围内项目(地市公司)：" label-width="12em"  @click="showdishiPick2 = (canEditdishi==true&&fromdata.city=='省重要客户中心')?true:false" :right-icon="canEditdishi&&fromdata.city=='省重要客户中心' ? 'arrow' : ''"/>
    <van-popup v-model="showdishiPick2" position="bottom" get-container="body">
      <van-picker show-toolbar :columns="showdishiPick2columns" @confirm="showdishiPick2onConfirm" @cancel="showdishiPick2 = false"/>
    </van-popup> 
    <van-field v-if="showNodishi2Filed==true" :readonly="canEditdishi!=true" required autosize type="textarea" rows="1" name="isOperateCityExplain" :value="fromdata.isOperateCityExplain" v-model="fromdata.isOperateCityExplain" label="是否公司经营范围内项目(地市公司)说明：" label-width="12em" :right-icon="canEditdishi ? 'arrow' : ''" :rules="[{ required: showNodishi1Filed, message: '请填写说明'}]"/>
    <!-- <van-field v-if="showxianquValue==true&&fromdata.city!='省重要客户中心'" readonly required name="isClaimCountyValue" :value="fromdata.isClaimCountyValue" label="是否认领(县区公司)：" label-width="10.5em" @click="showxianquPick1 = (canEditxianqu==true)?true:false" :right-icon="canEditxianqu ? 'arrow' : ''"/>
    <van-popup v-model="showxianquPick1" position="bottom" get-container="body">
      <van-picker show-toolbar :columns="showxianquPick1columns" @confirm="showxianquPick1onConfirm" @cancel="showxianquPick1 = false"/>
    </van-popup> 
    <van-field v-if="showNoxianqu1Filed==true&&showxianquValue==true&&fromdata.city!= '省重要客户中心'" :readonly="canEditxianqu!=true" required autosize type="textarea" rows="1" name="isClaimCountyDescription" :value="fromdata.isClaimCountyDescription" v-model="fromdata.isClaimCountyDescription" label="非本县区项目说明：" label-width="9em" :right-icon="canEditxianqu ? 'arrow' : ''" :rules="[{ required: showNoxianqu1Filed, message: '请填写说明'}]"/>
    <van-field v-if="showxianquValue==true&&fromdata.city!='省重要客户中心'" readonly required name="isOperateCounties" :value="fromdata.isOperateCounties" label="是否公司经营范围内项目(县区公司)：" label-width="12em" @click="showxianquPick2 = (canEditxianqu==true)?true:false" :right-icon="canEditxianqu ? 'arrow' : ''"/>
    <van-popup v-model="showxianquPick2" position="bottom" get-container="body">
      <van-picker show-toolbar :columns="showxianquPick2columns" @confirm="showxianquPick2onConfirm" @cancel="showxianquPick2 = false"/>
    </van-popup> 
    <van-field v-if="showxianquValue==true&&showNoxianqu2Filed==true&&fromdata.city!= '省重要客户中心'" :readonly="canEditxianqu!=true" required autosize type="textarea" rows="1" name="isOperateCountiesExplain" :value="fromdata.isOperateCountiesExplain" v-model="fromdata.isOperateCountiesExplain" label="是否公司经营范围内项目(县区公司)说明：" label-width="12em" :right-icon="canEditxianqu ? 'arrow' : ''" :rules="[{ required: showNoxianqu2Filed, message: '请填写说明'}]"/> -->
    <van-field v-if="showxianquValue==true&&fromdata.city!='省重要客户中心'" readonly required name="isClaimCountyValue" :value="fromdata.isClaimCountyValue" label="是否认领(县区公司)：" label-width="10.5em" />
    <van-field v-if="showNoxianqu1Filed==true&&showxianquValue==true&&fromdata.city!= '省重要客户中心'" readonly required autosize type="textarea" rows="1" name="isClaimCountyDescription" :value="fromdata.isClaimCountyDescription" label="非本县区项目说明：" label-width="9em"/>
    <van-field v-if="showxianquValue==true&&fromdata.city!='省重要客户中心'" readonly required name="isOperateCounties" :value="fromdata.isOperateCounties" label="是否公司经营范围内项目(县区公司)：" label-width="12em"/>
    <van-field v-if="showxianquValue==true&&showNoxianqu2Filed==true&&fromdata.city!= '省重要客户中心'" readonly required autosize type="textarea" rows="1" name="isOperateCountiesExplain" :value="fromdata.isOperateCountiesExplain" label="是否公司经营范围内项目(县区公司)说明：" label-width="12em"/>
    <div v-if="showcChengbanView == true">
      <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
        <div class="blue_item" />
        <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">审批</span> 
      </div>
      <van-field readonly name="auditResults" :value="fromdata.auditResults" label="审核结果：" label-width="5em" />
      <van-field :readonly="canEditchengban==false" v-model="fromdata.auditOpinion" autosize type="textarea" rows="1" name="auditOpinion" :value="fromdata.auditOpinion" label="审核意见：" label-width="5em" :right-icon="canEditchengban ? 'arrow' : ''"/>
      <van-field readonly name="auditPeople" :value="fromdata.auditPeople" label="审核人：" label-width="4em" />

      <van-field readonly required name="isEmphasis" :value="fromdata.isEmphasis" label="是否共性(重点)项目：" label-width="10.5em" @click="showgongxingPick1 = (canEditchengban==true)?true:false" :right-icon="canEditchengban ? 'arrow' : ''" :rules="[{ required: canEditchengban, message: '请填写是否共性(重点)项目' }]"/>

      
      <van-popup v-model="showgongxingPick1" position="bottom" get-container="body">
        <van-picker show-toolbar :columns="showgongxingPick1columns" @confirm="showgongxingPick1onConfirm" @cancel="showgongxingPick1 = false"/>
      </van-popup> 
      <van-field v-if="showgongxingPick2View==true" readonly required name="emphasisName" :value="fromdata.emphasisName" label="共性(重点)项目名称：" label-width="10.5em" @click="canEditchengban==true||canEditgongxing==true?queryByType():''" :right-icon="canEditchengban||canEditgongxing ? 'arrow' : ''"/>
      <van-popup v-if="showgongxingPick2View==true" v-model="showgongxingPick2" position="bottom" get-container="body">
        <van-picker show-toolbar :columns="showgongxingPick2columns" @confirm="showgongxingPick2onConfirm" @cancel="showgongxingPick2 = false"/>
      </van-popup>
    </div>
    <historyAndSuggs id='target' :showHistory='showHistory'
            :historydata='historydata' :approveList='approveList' />
    </div>
  </div>
</template>
 
<script>
import { getCountyByParentOrgCode,queryByType } from '@/api/dictapi'
import { openFileUrl } from '@/store/openFile'
import historyAndSuggs from "@/views/srqr/historyAndSuggs.vue"
import { mapGetters } from "vuex"
export default {
  data() {
    return {
      canEditdishi:false,
      showxianquValue:false,
      canEditxianqu:false,
      showdishiPick1:false,
      showdishiPick1columns:['认领(本公司客户)','不认领(非本公司客户)'],
      showNodishi1Filed:false,
      showdishiPick2:false,
      showdishiPick2columns:['是','否'],
      showNodishi2Filed:false,
      showxianquPick1:false,
      showxianquPick1columns:['认领(本县区客户)','不认领(非本县区客户)'],
      showNoxianqu1Filed:false,
      showxianquPick2:false,
      showxianquPick2columns:['是','否'],
      showNoxianqu2Filed:false,
      showcountiesPick :false,
      showcountiesPickcolumns:[],
      countiesList:[],
      canEditcountiesPick:false,
      showcChengbanView:true,
      hasSetdata:false,
      canEditchengban:false,
      showgongxingPick1:false,
      showgongxingPick1columns:['是','否'],
      showgongxingPick2View:false,
      showgongxingPick2:false,
      showgongxingPick2columns:[],
      canEditgongxing:false
    }
  },
  computed: {
    ...mapGetters(['user']),
  },
  props: ['location','todotype','titledata','businessdata','fromdata','showHistory','historydata','approveList'],
  created(){
    
  },
  watch: {
    fromdata: {
      handler () { //这是vue的规定写法，当你watch的值发生变化的时候，就会触发这个handler，这是vue内部帮你做的事情
        console.log('changeFromdata list changed')
        this.$emit('freshData',this.fromdata)
        if (this.hasSetdata==false){
          if((this.location=='dict.startToSecondAdmin'||this.location=='dict.startToSecondAdminTrun')&&this.todotype==true){
            this.canEditdishi=true;
            if (this.fromdata.city!='省重要客户中心'){
              this.canEditcountiesPick=true;  
            }else{
              this.canEditcountiesPick=false;  
            }
          }else{
            this.canEditdishi=false;
          }
           console.log('changeFromdata'+this.fromdata.city+this.location)
          if(this.fromdata.city!='省重要客户中心'&&this.location!='dict.startToSecondAdmin'&&this.location!='dict.startToSecondAdminTrun'&&(this.location=='dict.secondAdminToThreeAdmin'||this.location=='dict.secondAdminToDepartmentInterior'
          ||this.location=='dict.startSpecialToIndustryLead'||this.fromdata.businessName)){
         
            this.showxianquValue=true;
            if(this.fromdata.dataSources=='分公司导入'){
              this.canEditxianqu=false
              this.fromdata.isClaimCounty='认领';
              this.fromdata.isOperateCounties='是';
            }else{
              if(this.todotype==true&&(this.location=='dict.secondAdminToThreeAdmin'||this.location=='dict.secondAdminToDepartmentInterior'
          ||this.location=='dict.startSpecialToIndustryLead')){
                this.canEditxianqu=true
              }
            }
          }else{
            this.canEditxianqu=false;
          }
          if(this.fromdata.isClaim=='认领'){
            this.fromdata.isClaimValue='认领(本公司客户)';
            this.showNodishi1Filed=false;
          }else if(this.fromdata.isClaim=='不认领'){
            this.fromdata.isClaimValue='不认领(非本公司客户)';
            this.showNodishi1Filed=true;
          }
          if(this.fromdata.isOperateCity=='是'){
            this.showNodishi2Filed=false;
          }else if(this.fromdata.isOperateCity=='否'){
            this.showNodishi2Filed=true;
          }
          if(this.fromdata.isClaimCounty=='认领'){
            this.fromdata.isClaimCountyValue='认领(本县区客户)';
            this.showNoxianqu1Filed=false
          }else if(this.fromdata.isClaimCounty=='不认领'){
            this.fromdata.isClaimCountyValue='不认领(非本县区客户)';
            this.showNoxianqu1Filed=true
          }
          if(this.fromdata.isOperateCounties=='是'){
            this.showNoxianqu2Filed=false;
          }else if(this.fromdata.isOperateCounties=='否'){
            this.showNoxianqu2Filed=true;
          }
          console.log('首次打开时加载了',this.fromdata.isEmphasis)
          if((this.location!='dict.start'&&this.location!='dict.startNoBelong'
          &&this.location!='dict.startToSecondAdmin'&&this.location!='dict.startToSecondAdminTrun')
          &&!(this.location=='dict.secondAdminToThreeAdmin'||this.location=='dict.secondAdminToDepartmentInterior'||this.location=='dict.startSpecialToIndustryLead')
          &&(this.location=='dict.specialLeadToSecondAdminTrun'||this.location=='dict.specialLeadToSecondAdmin'
          ||this.location=='dict.departmentInteriorToLead'||this.location=='dict.leadToSecondAdmin'
          ||this.location=='dict.managementLeadToOneAdmin'||this.location=='dict.oneAdminTurn'
          ||this.location=='dict.oneAdminToTurn'||this.location=='dict.secondAdminToTurn'
          ||this.location=='dict.threeAdminToLead'||this.location=='dict.departmentInteriorToAdmin'
          ||this.location=='dict.leadToManagementLead'||this.location=='dict.leadToSolutionManager'
              ||this.location=='dict.secondAdminToLead'||this.fromdata.isEmphasis!=null)){
            console.log('首次打开时加载了',this.location)
            if((this.location=='dict.specialLeadToSecondAdmin'||this.location=='dict.departmentInteriorToLead'||
              this.location=='dict.leadToSecondAdmin'||this.location=='dict.secondAdminToTurn'||
              this.location=='dict.specialLeadToSecondAdminTrun'||this.location=='dict.managementLeadToOneAdmin'||
              this.location=='dict.oneAdminTurn'||this.location=='dict.oneAdminTurn'||
              this.location=='dict.secondAdminToTurn'||this.location=='dict.threeAdminToLead'||
              this.location=='dict.specialLeadToSecondAdmin'||this.location=='dict.specialLeadToSecondAdminTrun'||
              this.location=='dict.departmentInteriorToAdmin'||this.location=='dict.departmentInteriorToLead'||
              this.location=='dict.leadToManagementLead'||this.location=='dict.leadToSolutionManager'
              ||this.location=='dict.secondAdminToLead'
              )&&this.todotype==true){
              console.log('首次打开时加载了',this.location)
              this.canEditchengban=true
            }else {
              this.canEditchengban=false
            }
            if(this.fromdata.isEmphasis == '是'){
              this.showgongxingPick2View=true;
            }else if(this.fromdata.isEmphasis == '否'){
              this.showgongxingPick2View=false;
            }
            this.showcChengbanView=true;  
          }else{
            this.showcChengbanView=false;
          } 
          if((this.location=='dict.leadToSolutionManagerZk'||
          this.location=='dict.secondAdminToLeadManager'||
          this.location=='dict.leadToManagementLead'||
          this.location=='dict.leadToSolutionManager'||
          this.location=='dict.solutionManagerToDirector'||
          this.location=='dict.directorToInfoManager')&&this.todotype==true){
            this.canEditgongxing=true
          }else{
            this.canEditgongxing=false
          }
        }
      },
      deep: true,  // 可以深度检测到 obj 对象的属性值的变化
      immediate: true //刷新加载  立马触发一次handler
    },
    
  }, 
  methods: {
    tomsg () {
      document.getElementById('target').scrollIntoView({ behavior: 'smooth' })
    },
    getCountyByParentOrgCode(){
      this.hasSetdata=true;
      getCountyByParentOrgCode({ parentOrgCode: this.fromdata.citiesCode } ,{ userName: this.user.userName })
        .then((result) => {
          if (!result.data) {
            Notify(result.message);
            return;
          }
          this.showcountiesPickcolumns=[];
          this.countiesList=[];
          for(var i=0;i<result.data.data.length;i++){
            this.showcountiesPickcolumns.push(result.data.data[i].ORGNAME);
          }
          this.countiesList=result.data.data;
          this.showcountiesPick=true;
        })
    },
    queryByType(){
      console.log('获取项目信息')
      this.hasSetdata=true;
      queryByType({ dictType:'emphasisType'} ,{ userName: this.user.userName })
        .then((result) => {
          if (!result.data) {
            Notify(result.message);
            return;
          }
          this.showgongxingPick2columns=[];
          for(var i=0;i<result.data.data.length;i++){
            this.showgongxingPick2columns.push(result.data.data[i].name);
          }
          this.showgongxingPick2=true;
        })
    },
    showcountiesPickonConfirm(value,index){
      this.hasSetdata=true;
      console.log('修改了县区')
      this.fromdata.countiesCode=this.countiesList[index].ORGCODE;
      this.fromdata.counties=value;
      this.showcountiesPick=false;
    },
    showdishiPick1onConfirm(value){
      this.hasSetdata=true;
      this.fromdata.isClaimValue=value;
      if(value == '认领(本公司客户)'){
          this.fromdata.isClaim='认领';
          this.showNodishi1Filed=false
      }else if(value == '不认领(非本公司客户)'){
          this.fromdata.isClaim='不认领';
          this.showNodishi1Filed=true
      }
      this.showdishiPick1=false;
    },
    showdishiPick2onConfirm(value){
      this.hasSetdata=true;
      this.fromdata.isOperateCity=value;
      if(value == '是'){
          this.showNodishi2Filed=false
      }else if(value == '否'){
          this.showNodishi2Filed=true
      }
      this.showdishiPick2=false;
    },
    showxianquPick1onConfirm(value){
      this.hasSetdata=true;
      this.fromdata.isClaimCountyValue=value;
      if(value == '认领(本县区客户)'){
          this.fromdata.isClaimCounty='认领';
          this.showNoxianqu1Filed=false
      }else if(value == '不认领(非本县区客户)'){
          this.fromdata.isClaimCounty='不认领';
          this.showNoxianqu1Filed=true
      }
      this.showxianquPick1=false;
    },
    showxianquPick2onConfirm(value){
      this.hasSetdata=true;
      this.fromdata.isOperateCounties=value;
      if(value == '是'){
          this.showNoxianqu2Filed=false
      }else if(value == '否'){
          this.showNoxianqu2Filed=true
      }
      this.showxianquPick2=false;
    },
    showgongxingPick1onConfirm(value){
      this.hasSetdata=true;
      this.fromdata.isEmphasis=value;
      if(value == '是'){
        this.showgongxingPick2View=true;
      }else if(value == '否'){
        this.showgongxingPick2View=false;
      }
      this.showgongxingPick1=false;
    },
    showgongxingPick2onConfirm(value){
      this.hasSetdata=true;
      this.fromdata.emphasisName=value
      this.showgongxingPick2=false
    },
    openFileUrlfun(value) {
      this.$router.push(
        {
          name: 'fileview',
          query: {
            openFileUrl: openFileUrl(value)
          }
        }
      );
    },
  },
  components: {
    historyAndSuggs
  },
}
</script>
 
<style>
.tables.el-table .cell {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    word-break: break-all;
    line-height: 15px;
    padding-left: 5px;
    padding-right: 5px;
}
</style>